<?php

class Product_ProductController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->layout->setLayout('layout-html');
	$contextSwitch = $this->_helper->getHelper('contextSwitch');
        $contextSwitch->addActionContext('edit', 'json')
		      ->addActionContext('list', array('json', 'xml'))
                      ->initContext();
    }

    public function indexAction()
    {
        // action body
    }

    public function editAction()
    {
        Zend_Dojo::enableView($this->view);
	Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
	$this->_helper->layout()->disableLayout();
//        $this->_helper->viewRenderer->setNoRender(true);
	
	$form = new Product_Form_Productform();
	
	if($this->getRequest()->isPost() && $form->isValid($_POST))
	{
	    $model = new Product_Model_DbTable_Product();
	    
	    $data = $form->getValues();
	    unset($data['product_submit']);
	    if(isset($data['product_id']))
	    {
		$model->update($data, 'product_id = '.$data['product_id']);
	    }
	    else
	    {
		$model->insert($data);
	    }
	    
	}
	
	$this->view->form = $form;
	$uploadForm = new Product_Form_Upload();
	$this->view->uploadForm = $uploadForm;
    }

    public function listAction()
    {
//        $this->_helper->layout()->disableLayout();
//        $this->_helper->viewRenderer->setNoRender(true);
	$model = new Product_Model_DbTable_Product();
	$items = $model->fetchAll()->toArray();
	$data = array();
	$this->view->identifier = 'product_id';
	$data['items'] = array();
	foreach ($items as $item)
	{
	    $data['items'][] = $item;
	}
	$this->view->items=$data['items'];
//	print_r($data);+
//	echo json_encode($data);
    }


}





